#ifndef CQtGpsSINGLE_H
#define CQtGpsSINGLE_H

#include <QObject>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QDateTime>
#include <QList>
#include <QString>
#include <QDebug>
class CQtGpsSingle : public QSerialPort
{
    Q_OBJECT
private: //构造私有
    explicit CQtGpsSingle(QObject *parent = 0);
    explicit CQtGpsSingle(const QSerialPortInfo &serialPortInfo, QObject *parent = nullptr);
    explicit CQtGpsSingle(const QString &strPortName, QSerialPort::BaudRate baud,QObject *parent = 0);

    static  CQtGpsSingle *m_instanse; //饿汉单例模式
    //用于垃圾自动回收
    class GarbageCollector {
    public:
        ~GarbageCollector() {
            if (CQtGpsSingle::m_instanse) {
                delete CQtGpsSingle::m_instanse;
                CQtGpsSingle::m_instanse = nullptr;
                qDebug()<<"huishou";
            }
        }
    };
    static GarbageCollector gc; //声明垃圾回收对象

public:
    //获得单利对象
    static CQtGpsSingle *GetSingelton()
    {
        return m_instanse;
    }

    //设置参数
    void setSerialPara(const QString &strPortName, QSerialPort::BaudRate baud);

    //获取属性
    int GetYY() const;
    int GetMM() const;
    int GetDD() const;
    int Gethh() const;
    int Getmm() const;
    int Getss() const;
    int Getms() const;
    QDateTime getCurrentTime() const;  //获取当前的时间

    QList<QSerialPortInfo> getPortInfo();
    float getLongitude() const;  //经度
    float getLatitude() const;   //纬度
    QString getLongitudeSign() const; //经度方向 E:东经 W：西经
    QString getLatitudeSign() const;  //纬度方向 N:北纬 S:南纬

signals:
    void signalGetReady(); //接受一次有效数据就发送一次信号
private:
    //gps解析参数
    int _YY;
    int _MM;
    int _DD;
    int _hh;
    int _mm;
    int _ss;
    int _ms;
    QDateTime _currentTime;
    float _longitude; //经度
    float _latitude; //纬度
    QString _longitudeSign; //经度方向 E:东经 W：西经
    QString _latitudeSign; //纬度方向 N:北纬 S:南纬

    void paraInit(); //初始化参数函数
    void dealRec(); //接受处理函数

public slots:
};

#endif // CQtGpsSingle_H


/*使用说明：
 * $GNRMC（推荐定位信息 $GNRMC,095554.000,A,2318.1327,N,11319.7252,E,000.0,005.7,081215,,,A*73
 * 无需创建一个类，继承serialort类
 *
#include "CQtGpsSingle.h"
#include <QDebug>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    CQtGpsSingle::GetSingelton()->setSerialPara("ttyUSB0",QSerialPort::Baud38400);
    qDebug()<< CQtGpsSingle::GetSingelton()->open(QIODevice::ReadWrite);
    CQtGpsSingle::GetSingelton()->write("123");
    if(CQtGpsSingle::GetSingelton()->isOpen()==true)
    {
        qDebug()<<tr("open true");
        CQtGpsSingle::GetSingelton()->write("hello");
        connect(gps,&CQtGpsSingle::signalGetReady,this,[=]
        {
            qDebug()<<"当前时刻："<<CQtGpsSingle::GetSingelton()->getCurrentTime()<<"纬度："<<CQtGpsSingle::GetSingelton()->getLatitudeSign()<<CQtGpsSingle::GetSingelton()->getLatitude()
            <<"纬度"<<CQtGpsSingle::GetSingelton()->getLongitudeSign()<<CQtGpsSingle::GetSingelton()->getLongitude();
        });
    }

    Widget w;
    w.show();

    return a.exec();
}


 *
 *
QDateTime time1 = QDateTime::fromString("2012-07-23 15:30:20", "yyyy-MM-dd hh:mm:ss");
*/
